﻿using LoveEat.API.Write.Applications.Commands.slaughter;
using LoveEat.Domain.slaughter;
using LoveEat.ErrorCode;
using LoveEat.Infrastructure.Interfaces;
using MediatR;
using Microsoft.AspNetCore.Server.HttpSys;

namespace LoveEat.API.Write.Applications.CommandHandlers.slaughter
{
    public class AddslaughterCommandHandler : IRequestHandler<AddslaughterCommand, APIResult<int>>
    {
        private readonly IBaseRespository<slaughterModel> slaugRep;

        public AddslaughterCommandHandler(IBaseRespository<slaughterModel> slaugRep)
        {
            this.slaugRep = slaugRep;
        }

        public async Task<APIResult<int>> Handle(AddslaughterCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.Code=APIResultCode.添加成功;
            result.Message=APIResultCode.添加成功.ToString();

            slaughterModel slaug=new slaughterModel();
            slaug.Batch=request.Batch;
            slaug.weight = request.weight;
            slaug.CreateTime=request.CreateTime;
            slaug.KillTime=request.KillTime;
            slaug.IsDelete = false;
            await slaugRep.AddAsync(slaug);



             
            return await Task.FromResult(result);
        }
    }
}
